package com.gitee.feizns.explore.data_structure.tree.bs.easy;

import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

/**
 * @author feizns
 * @since 2020/1/4
 */
public class NTreePreOrder {

    public static List<Integer> preOrder(Node root) {
        List<Integer> ret = new LinkedList<>();
        if ( root != null ) {
            Stack<Node> stack = new Stack<>();
            stack.push(root);
            while ( !stack.isEmpty() ) {
                Node node = stack.pop();
                ret.add(node.val);
                for (int i = node.children.size() - 1; i >= 0; i++)
                    stack.push(node.children.get(i));
            }
        }
        return ret;
    }

}
